<template>
  <div class="home-container">
    <!-- 轮播图部分 -->
    <div class="carousel">
      <div class="carousel-inner" :style="{ transform: `translateX(-${currentSlide * 100}%)` }">
        <div class="carousel-item" v-for="(slide, index) in slides" :key="index">
          <img :src="slide.image" :alt="slide.title">
          <div class="carousel-caption">
            <h2>{{ slide.title }}</h2>
            <p>{{ slide.description }}</p>
          </div>
        </div>
      </div>
      <div class="carousel-indicators">
        <span 
          v-for="(slide, index) in slides" 
          :key="index" 
          :class="{ active: currentSlide === index }"
          @click="setSlide(index)">
        </span>
      </div>
      <button class="carousel-control prev" @click="prevSlide">&lt;</button>
      <button class="carousel-control next" @click="nextSlide">&gt;</button>
    </div>

    <!-- 特色部分 -->
    <section class="features">
      <h2 class="section-title">我们的特色</h2>
      <div class="feature-cards">
        <div class="feature-card" v-for="(feature, index) in features" :key="index">
          <div class="feature-icon">{{ feature.icon }}</div>
          <h3>{{ feature.title }}</h3>
          <p>{{ feature.description }}</p>
        </div>
      </div>
    </section>

    <!-- 产品展示和新闻部分并排显示 -->
    <div class="content-columns">
      <!-- 产品展示部分 -->
      <section class="products">
        <h2 class="section-title">热门产品</h2>
        <div class="product-grid">
          <div class="product-card" v-for="(product, index) in products" :key="index">
            <div class="product-image">
              <img :src="product.image" :alt="product.name">
            </div>
            <div class="product-info">
              <h3>{{ product.name }}</h3>
              <p class="product-price">¥{{ product.price }}</p>
              <p class="product-description">{{ product.description }}</p>
              <button class="btn-primary">查看详情</button>
            </div>
          </div>
        </div>
      </section>

      <!-- 新闻动态部分 -->
      <section class="news">
        <h2 class="section-title">最新动态</h2>
        <div class="news-list">
          <div class="news-item" v-for="(item, index) in news" :key="index">
            <div class="news-date">
              <span class="day">{{ item.day }}</span>
              <span class="month">{{ item.month }}</span>
            </div>
            <div class="news-content">
              <h3>{{ item.title }}</h3>
              <p>{{ item.summary }}</p>
              <a href="#" class="read-more">阅读更多</a>
            </div>
          </div>
        </div>
      </section>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';

// 轮播图数据
const slides = ref([
  {
    title: '欢迎访问我们的网站',
    description: '探索更多精彩内容和服务',
    image: 'https://picsum.photos/id/1018/1000/400'
  },
  {
    title: '专业的团队',
    description: '为您提供最优质的服务',
    image: 'https://picsum.photos/id/1015/1000/400'
  },
  {
    title: '创新的解决方案',
    description: '助力您的业务蓬勃发展',
    image: 'https://picsum.photos/id/1019/1000/400'
  }
]);

// 特色数据
const features = ref([
  {
    icon: '🚀',
    title: '快速部署',
    description: '我们的解决方案可以快速部署，让您的业务立即启动'
  },
  {
    icon: '🔒',
    title: '安全可靠',
    description: '采用最先进的安全技术，保障您的数据安全'
  },
  {
    icon: '💡',
    title: '创新设计',
    description: '独特的设计理念，为您的产品增添亮点'
  },
  {
    icon: '🔧',
    title: '全面支持',
    description: '7x24小时技术支持，解决您的任何问题'
  }
]);

// 产品数据
const products = ref([
  {
    name: '智能手表',
    price: 1299,
    description: '全新一代智能手表，支持健康监测和运动追踪',
    image: 'https://picsum.photos/id/26/300/200'
  },
  {
    name: '无线耳机',
    price: 899,
    description: '高品质音效，长效续航，舒适佩戴体验',
    image: 'https://picsum.photos/id/27/300/200'
  },
  {
    name: '智能音箱',
    price: 599,
    description: '语音控制，智能家居中心，音质出众',
    image: 'https://picsum.photos/id/28/300/200'
  }
]);

// 新闻数据
const news = ref([
  {
    title: '公司荣获2023年度创新企业奖',
    summary: '在昨日举行的科技创新大会上，我公司凭借优秀的产品和服务获得了年度创新企业奖...',
    day: '15',
    month: '6月'
  },
  {
    title: '新一代产品发布会即将举行',
    summary: '我们将于下月举行新产品发布会，届时将展示多款创新产品，敬请期待...',
    day: '28',
    month: '5月'
  },
  {
    title: '技术团队分享最新研发成果',
    summary: '我们的技术团队在人工智能领域取得了突破性进展，相关成果已申请专利保护...',
    day: '10',
    month: '5月'
  }
]);

// 轮播图逻辑
const currentSlide = ref(0);
let slideInterval: number | null = null;

const nextSlide = () => {
  currentSlide.value = (currentSlide.value + 1) % slides.value.length;
};

const prevSlide = () => {
  currentSlide.value = (currentSlide.value - 1 + slides.value.length) % slides.value.length;
};

const setSlide = (index: number) => {
  currentSlide.value = index;
};

// 自动轮播
onMounted(() => {
  slideInterval = window.setInterval(() => {
    nextSlide();
  }, 5000);
});

onBeforeUnmount(() => {
  if (slideInterval) {
    clearInterval(slideInterval);
  }
});
</script>

<style scoped>
/* PC端优化的首页样式 */
.home-container {
  max-width: 100%;
  margin: 0 auto;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  color: #333;
}

.section-title {
  text-align: center;
  margin: 40px 0 30px;
  color: #2c3e50;
  font-size: 28px;
  font-weight: 500;
  position: relative;
}

.section-title::after {
  content: '';
  display: block;
  width: 60px;
  height: 3px;
  background: linear-gradient(to right, #42b983, #64d5ca);
  margin: 10px auto 0;
  border-radius: 3px;
}

/* 轮播图样式 */
.carousel {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
  margin-bottom: 40px;
  height: 450px;
}

.carousel-inner {
  display: flex;
  transition: transform 0.5s ease;
  height: 100%;
}

.carousel-item {
  min-width: 100%;
  position: relative;
}

.carousel-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.carousel-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  color: white;
}

.carousel-caption h2 {
  margin: 0 0 10px;
  font-size: 32px;
}

.carousel-indicators {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}

.carousel-indicators span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all 0.3s ease;
}

.carousel-indicators span.active {
  background-color: white;
  transform: scale(1.2);
}

.carousel-control {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.3);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.carousel-control:hover {
  background-color: rgba(255, 255, 255, 0.5);
}

.carousel-control.prev {
  left: 20px;
}

.carousel-control.next {
  right: 20px;
}

/* 特色部分样式 */
.features {
  margin: 60px 0;
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 30px;
}

.feature-card {
  background-color: white;
  border-radius: 10px;
  padding: 30px;
  text-align: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.feature-icon {
  font-size: 40px;
  margin-bottom: 20px;
}

.feature-card h3 {
  margin: 0 0 15px;
  color: #2c3e50;
  font-size: 20px;
}

.feature-card p {
  color: #666;
  line-height: 1.6;
}

/* 内容列布局 */
.content-columns {
  display: flex;
  gap: 30px;
  margin: 60px 0;
}

/* 产品展示样式 */
.products {
  flex: 3;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30px;
}

.product-card {
  background-color: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease;
  height: 100%;
}

.product-card:hover {
  transform: translateY(-5px);
}

.product-image {
  height: 200px;
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.product-card:hover .product-image img {
  transform: scale(1.05);
}

.product-info {
  padding: 20px;
}

.product-info h3 {
  margin: 0 0 10px;
  color: #2c3e50;
  font-size: 18px;
}

.product-price {
  color: #42b983;
  font-weight: bold;
  font-size: 18px;
  margin: 10px 0;
}

.product-description {
  color: #666;
  margin-bottom: 20px;
  line-height: 1.5;
}

.btn-primary {
  background-color: #42b983;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.btn-primary:hover {
  background-color: #3aa876;
}

/* 新闻动态样式 */
.news {
  flex: 2;
}

.news-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.news-item {
  display: flex;
  background-color: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.news-date {
  min-width: 80px;
  background-color: #42b983;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 15px;
}

.news-date .day {
  font-size: 24px;
  font-weight: bold;
}

.news-date .month {
  font-size: 14px;
}

.news-content {
  padding: 20px;
  flex-grow: 1;
}

.news-content h3 {
  margin: 0 0 10px;
  color: #2c3e50;
  font-size: 18px;
}

.news-content p {
  color: #666;
  margin-bottom: 15px;
  line-height: 1.5;
}

.read-more {
  color: #42b983;
  text-decoration: none;
  font-weight: 500;
  display: inline-block;
  transition: color 0.3s ease;
}

.read-more:hover {
  color: #3aa876;
}
</style>